<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Socialite extends Model
{
    public $fillable = [
        'user_id', 'driver', 'slug'
    ];

    const WECHAT = 'wechat';//微信授权

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function isDriver($driver)
    {
        return $driver == $this->driver;
    }

    public function isWechat()
    {
        return $this->isDriver(self::WECHAT);
    }

    public function getOpenid(): string
    {
        if ($this->isWechat()) {
            return $this->slug;
        }
        return '';
    }
}
